package deliciouse.biz.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import deliciouse.biz.CategoryBiz;
import deliciouse.dao.CategoryDao;
import deliciouse.entity.Category;
import deliciouse.util.MybatisUtil;

public class CategoryBizImpl implements CategoryBiz {

	@Override
	public List<Category> getAll() {
		SqlSession sess = MybatisUtil.OpenSession();
		try{
			CategoryDao dao =sess.getMapper(CategoryDao.class);
			List<Category> categorylist=dao.getAll();
			return categorylist;
		}finally{
			sess.close();
		}
	}

	@Override
	public Category fetchById(int id) {
		SqlSession sess = MybatisUtil.OpenSession();
		try{
			CategoryDao dao =sess.getMapper(CategoryDao.class);
			Category category =dao.fetchById(id);
			return category;
		}finally{
			sess.close();
		}
	}

	@Override
	public void update(Category category) {
		SqlSession sess = MybatisUtil.OpenSession();
		try{
			CategoryDao dao =sess.getMapper(CategoryDao.class);
			dao.update(category);
			sess.commit();
		}finally{
			sess.close();
		}
	}

}
